*------------------------------------------------------------------------------*
					*** FIGURE S3. INCUMBENT-OPPOSITION PARTIES ***
*------------------------------------------------------------------------------*

use "${tempdata}kreise_complete_all.dta", clear

*Keep sample period
drop if year < 2000

*------------------------------------------------------------------------------*

***Generate Incumbent parties in each election
gen Incumbent_parties = ""

	//BW
	replace Incumbent_parties = "SPD + FDP " if election_typeBWorLW == "BW" & election_date == td(05oct1980)
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "BW" & election_date == td(06mar1983)
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "BW" & election_date == td(25jan1987)
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "BW" & election_date == td(02dec1990)
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "BW" & election_date == td(16oct1994)
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "BW" & election_date == td(27sep1998)
	replace Incumbent_parties = "SPD + GRUNE" if election_typeBWorLW == "BW" & election_date == td(22sep2002)
	replace Incumbent_parties = "SPD + GRUNE" if election_typeBWorLW == "BW" & election_date == td(18sep2005)
	replace Incumbent_parties = "CDU + SPD" if election_typeBWorLW == "BW" & election_date == td(27sep2009)
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "BW" & election_date == td(22sep2013)
	replace Incumbent_parties = "CDU + SPD" if election_typeBWorLW == "BW" & election_date == td(24sep2017)
	
	//LW : Baden-Württemberg
	replace Incumbent_parties = "CDU" if election_typeBWorLW == "LW" & election_date == td(16mar1980) & Land == "Baden_Württemberg"
	replace Incumbent_parties = "CDU" if election_typeBWorLW == "LW" & election_date == td(25mar1984) & Land == "Baden_Württemberg"
	replace Incumbent_parties = "CDU" if election_typeBWorLW == "LW" & election_date == td(20mar1988) & Land == "Baden_Württemberg"
	replace Incumbent_parties = "CDU" if election_typeBWorLW == "LW" & election_date == td(05apr1992) & Land == "Baden_Württemberg"
	replace Incumbent_parties = "CDU + SPD" if election_typeBWorLW == "LW" & election_date == td(24mar1996) & Land == "Baden_Württemberg"
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "LW" & election_date == td(25mar2001) & Land == "Baden_Württemberg"
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "LW" & election_date == td(26mar2006) & Land == "Baden_Württemberg"
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "LW" & election_date == td(27mar2011) & Land == "Baden_Württemberg"
	replace Incumbent_parties = "SPD + GRUNE" if election_typeBWorLW == "LW" & election_date == td(13mar2016) & Land == "Baden_Württemberg"
	
	//LW : Bayern
	replace Incumbent_parties = "CDU" if election_typeBWorLW == "LW" & election_date == td(10oct1982) & Land == "Bayern"
	replace Incumbent_parties = "CDU" if election_typeBWorLW == "LW" & election_date == td(12oct1986) & Land == "Bayern"
	replace Incumbent_parties = "CDU" if election_typeBWorLW == "LW" & election_date == td(14oct1990) & Land == "Bayern"
	replace Incumbent_parties = "CDU" if election_typeBWorLW == "LW" & election_date == td(05apr1992) & Land == "Bayern"
	replace Incumbent_parties = "CDU" if election_typeBWorLW == "LW" & election_date == td(25sep1994) & Land == "Bayern"
	replace Incumbent_parties = "CDU" if election_typeBWorLW == "LW" & election_date == td(13sep1998) & Land == "Bayern"
	replace Incumbent_parties = "CDU" if election_typeBWorLW == "LW" & election_date == td(21sep2003) & Land == "Bayern"
	replace Incumbent_parties = "CDU" if election_typeBWorLW == "LW" & election_date == td(28sep2008) & Land == "Bayern"
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "LW" & election_date == td(15sep2013) & Land == "Bayern"
	replace Incumbent_parties = "CDU" if election_typeBWorLW == "LW" & election_date == td(14oct2018) & Land == "Bayern"
	
	//LW : Berlin
	replace Incumbent_parties = "CDU + SPD" if election_typeBWorLW == "LW" & election_date == td(22oct1995) & Land == "Berlin"
	replace Incumbent_parties = "CDU + SPD" if election_typeBWorLW == "LW" & election_date == td(10oct1999) & Land == "Berlin"
	replace Incumbent_parties = "CDU + SPD" if election_typeBWorLW == "LW" & election_date == td(21oct2001) & Land == "Berlin"
	replace Incumbent_parties = "SPD + DIELINKE" if election_typeBWorLW == "LW" & election_date == td(17sep2006) & Land == "Berlin"
	replace Incumbent_parties = "SPD + DIELINKE" if election_typeBWorLW == "LW" & election_date == td(18sep2011) & Land == "Berlin"
	replace Incumbent_parties = "SPD + CDU" if election_typeBWorLW == "LW" & election_date == td(18sep2016) & Land == "Berlin"
	
	//LW : Brandenburg
	replace Incumbent_parties = "SPD + FDP + GRUNE" if election_typeBWorLW == "LW" & election_date == td(11sep1994) & Land == "Brandenburg"
	replace Incumbent_parties = "SPD" if election_typeBWorLW == "LW" & election_date == td(05sep1999) & Land == "Brandenburg"
	replace Incumbent_parties = "SPD + CDU" if election_typeBWorLW == "LW" & election_date == td(19sep2004) & Land == "Brandenburg"
	replace Incumbent_parties = "SPD + CDU" if election_typeBWorLW == "LW" & election_date == td(27sep2009) & Land == "Brandenburg"
	replace Incumbent_parties = "SPD + DIELINKE" if election_typeBWorLW == "LW" & election_date == td(14sep2014) & Land == "Brandenburg"
	replace Incumbent_parties = "SPD + DIELINKE" if election_typeBWorLW == "LW" & election_date == td(1sep2019) & Land == "Brandenburg"
	
	//LW : Bremen
	replace Incumbent_parties = "SPD" if election_typeBWorLW == "LW" & election_date == td(25sep1983) & Land == "Bremen"
	replace Incumbent_parties = "SPD" if election_typeBWorLW == "LW" & election_date == td(13sep1987) & Land == "Bremen"
	replace Incumbent_parties = "SPD" if election_typeBWorLW == "LW" & election_date == td(29sep1991) & Land == "Bremen"
	replace Incumbent_parties = "SPD + FDP + GRUNE" if election_typeBWorLW == "LW" & election_date == td(14may1995) & Land == "Bremen"
	replace Incumbent_parties = "SPD + CDU" if election_typeBWorLW == "LW" & election_date == td(06jun1999) & Land == "Bremen"
	replace Incumbent_parties = "SPD + CDU" if election_typeBWorLW == "LW" & election_date == td(25may2003) & Land == "Bremen"
	replace Incumbent_parties = "SPD + CDU" if election_typeBWorLW == "LW" & election_date == td(13may2007) & Land == "Bremen"
	replace Incumbent_parties = "SPD + GRUNE" if election_typeBWorLW == "LW" & election_date == td(22may2011) & Land == "Bremen"
	replace Incumbent_parties = "SPD + GRUNE" if election_typeBWorLW == "LW" & election_date == td(10may2015) & Land == "Bremen"
	replace Incumbent_parties = "SPD + GRUNE" if election_typeBWorLW == "LW" & election_date == td(26may2019) & Land == "Bremen"
	
	//LW : Hamburg
	replace Incumbent_parties = "SPD" if election_typeBWorLW == "LW" & election_date == td(06jun1982) & Land == "Hamburg"
	replace Incumbent_parties = "SPD" if election_typeBWorLW == "LW" & election_date == td(09nov1986) & Land == "Hamburg"
	replace Incumbent_parties = "SPD + FDP" if election_typeBWorLW == "LW" & election_date == td(02may1991) & Land == "Hamburg"
	replace Incumbent_parties = "SPD" if election_typeBWorLW == "LW" & election_date == td(19sep1993) & Land == "Hamburg"
	replace Incumbent_parties = "SPD + STATTPARTEI" if election_typeBWorLW == "LW" & election_date == td(21sep1997) & Land == "Hamburg"
	replace Incumbent_parties = "SPD + GRUNE" if election_typeBWorLW == "LW" & election_date == td(23sep2001) & Land == "Hamburg"
	replace Incumbent_parties = "CDU + FDP + SCHILL" if election_typeBWorLW == "LW" & election_date == td(29feb2004) & Land == "Hamburg"
	replace Incumbent_parties = "CDU" if election_typeBWorLW == "LW" & election_date == td(27feb2008) & Land == "Hamburg"
	replace Incumbent_parties = "CDU + GRUNE" if election_typeBWorLW == "LW" & election_date == td(20feb2011) & Land == "Hamburg"
	replace Incumbent_parties = "SPD" if election_typeBWorLW == "LW" & election_date == td(15feb2015) & Land == "Hamburg"
	
	//LW : Hessen
	replace Incumbent_parties = "SPD + FDP" if election_typeBWorLW == "LW" & election_date == td(26sep1982) & Land == "Hessen"
	replace Incumbent_parties = "CDU" if election_typeBWorLW == "LW" & election_date == td(20jan1991) & Land == "Hessen"
	replace Incumbent_parties = "SPD + GRUNE" if election_typeBWorLW == "LW" & election_date == td(07feb1999) & Land == "Hessen"
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "LW" & election_date == td(02feb2003) & Land == "Hessen"
	replace Incumbent_parties = "CDU" if election_typeBWorLW == "LW" & election_date == td(27jan2008) & Land == "Hessen"
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "LW" & election_date == td(22sep2013) & Land == "Hessen"
	replace Incumbent_parties = "CDU + GRUNE" if election_typeBWorLW == "LW" & election_date == td(28oct2018) & Land == "Hessen"
	
	//LW : Mecklenburg-Vorpommern
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "LW" & election_date == td(16oct1994) & Land == "Mecklenburg_Vorpommern"
	replace Incumbent_parties = "CDU + SPD" if election_typeBWorLW == "LW" & election_date == td(27sep1998) & Land == "Mecklenburg_Vorpommern"
	replace Incumbent_parties = "SPD + DIELINKE" if election_typeBWorLW == "LW" & election_date == td(22sep2002) & Land == "Mecklenburg_Vorpommern"
	replace Incumbent_parties = "SPD + DIELINKE" if election_typeBWorLW == "LW" & election_date == td(17sep2006) & Land == "Mecklenburg_Vorpommern"
	replace Incumbent_parties = "SPD + CDU" if election_typeBWorLW == "LW" & election_date == td(04sep2011) & Land == "Mecklenburg_Vorpommern"
	replace Incumbent_parties = "SPD + CDU" if election_typeBWorLW == "LW" & election_date == td(04sep2016) & Land == "Mecklenburg_Vorpommern"
	
	//LW : Niedersachsen
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "LW" & election_date == td(13may1990) & Land == "Niedersachsen"
	replace Incumbent_parties = "SPD + GRUNE" if election_typeBWorLW == "LW" & election_date == td(13mar1994) & Land == "Niedersachsen"
	replace Incumbent_parties = "SPD" if election_typeBWorLW == "LW" & election_date == td(01mar1998) & Land == "Niedersachsen"
	replace Incumbent_parties = "SPD" if election_typeBWorLW == "LW" & election_date == td(02feb2003) & Land == "Niedersachsen"
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "LW" & election_date == td(27jan2008) & Land == "Niedersachsen"
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "LW" & election_date == td(20jan2013) & Land == "Niedersachsen"
	replace Incumbent_parties = "SPD + GRUNE" if election_typeBWorLW == "LW" & election_date == td(15oct2017) & Land == "Niedersachsen"
	
	//LW : Nordrhein-Westfalen
	replace Incumbent_parties = "SPD + FDP" if election_typeBWorLW == "LW" & election_date == td(11may1980) & Land == "Nordrhein_Westfalen"
	replace Incumbent_parties = "SPD" if election_typeBWorLW == "LW" & election_date == td(12may1985) & Land == "Nordrhein_Westfalen"
	replace Incumbent_parties = "SPD" if election_typeBWorLW == "LW" & election_date == td(13may1990) & Land == "Nordrhein_Westfalen"
	replace Incumbent_parties = "SPD" if election_typeBWorLW == "LW" & election_date == td(14may1995) & Land == "Nordrhein_Westfalen"
	replace Incumbent_parties = "SPD + GRUNE" if election_typeBWorLW == "LW" & election_date == td(14may2000) & Land == "Nordrhein_Westfalen"
	replace Incumbent_parties = "SPD + GRUNE" if election_typeBWorLW == "LW" & election_date == td(22may2005) & Land == "Nordrhein_Westfalen"
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "LW" & election_date == td(09may2010) & Land == "Nordrhein_Westfalen"
	replace Incumbent_parties = "SPD + GRUNE" if election_typeBWorLW == "LW" & election_date == td(13may2012) & Land == "Nordrhein_Westfalen"
	replace Incumbent_parties = "SPD + GRUNE" if election_typeBWorLW == "LW" & election_date == td(14may2017) & Land == "Nordrhein_Westfalen"
	
	//LW : Rheinland-Pfalz
	replace Incumbent_parties = "CDU" if election_typeBWorLW == "LW" & election_date == td(06mar1983) & Land == "Rheinland_Pfalz"
	replace Incumbent_parties = "CDU" if election_typeBWorLW == "LW" & election_date == td(17may1987) & Land == "Rheinland_Pfalz"
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "LW" & election_date == td(21apr1991) & Land == "Rheinland_Pfalz"
	replace Incumbent_parties = "SPD + FDP" if election_typeBWorLW == "LW" & election_date == td(24mar1996) & Land == "Rheinland_Pfalz"
	replace Incumbent_parties = "SPD + FDP" if election_typeBWorLW == "LW" & election_date == td(25mar2001) & Land == "Rheinland_Pfalz"
	replace Incumbent_parties = "SPD + FDP" if election_typeBWorLW == "LW" & election_date == td(26mar2006) & Land == "Rheinland_Pfalz"
	replace Incumbent_parties = "SPD" if election_typeBWorLW == "LW" & election_date == td(27mar2011) & Land == "Rheinland_Pfalz"
	replace Incumbent_parties = "SPD + GRUNE" if election_typeBWorLW == "LW" & election_date == td(13mar2016) & Land == "Rheinland_Pfalz"
	
	//LW : Saarland
	replace Incumbent_parties = "CDU + SPD" if election_typeBWorLW == "LW" & election_date == td(27apr1980) & Land == "Saarland"
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "LW" & election_date == td(10mar1985) & Land == "Saarland"
	replace Incumbent_parties = "SPD" if election_typeBWorLW == "LW" & election_date == td(28jan1990) & Land == "Saarland"
	replace Incumbent_parties = "SPD" if election_typeBWorLW == "LW" & election_date == td(16oct1994) & Land == "Saarland"
	replace Incumbent_parties = "SPD" if election_typeBWorLW == "LW" & election_date == td(05sep1999) & Land == "Saarland"
	replace Incumbent_parties = "CDU" if election_typeBWorLW == "LW" & election_date == td(05sep2004) & Land == "Saarland"
	replace Incumbent_parties = "CDU" if election_typeBWorLW == "LW" & election_date == td(30aug2009) & Land == "Saarland"
	replace Incumbent_parties = "CDU + FDP + GRUNE" if election_typeBWorLW == "LW" & election_date == td(25mar2012) & Land == "Saarland"
	replace Incumbent_parties = "CDU + SPD" if election_typeBWorLW == "LW" & election_date == td(26mar2017) & Land == "Saarland"
	
	//LW : Sachsen
	replace Incumbent_parties = "CDU" if election_typeBWorLW == "LW" & election_date == td(11sep1994) & Land == "Sachsen"
	replace Incumbent_parties = "CDU" if election_typeBWorLW == "LW" & election_date == td(19sep1999) & Land == "Sachsen"
	replace Incumbent_parties = "CDU" if election_typeBWorLW == "LW" & election_date == td(19sep2004) & Land == "Sachsen"
	replace Incumbent_parties = "CDU + SPD" if election_typeBWorLW == "LW" & election_date == td(30aug2009) & Land == "Sachsen"
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "LW" & election_date == td(31aug2014) & Land == "Sachsen"
	
	//LW : Sachsen-Anhalt
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "LW" & election_date == td(26jun1994) & Land == "Sachsen_Anhalt"
	replace Incumbent_parties = "SPD + GRUNE" if election_typeBWorLW == "LW" & election_date == td(26apr1998) & Land == "Sachsen_Anhalt"
	replace Incumbent_parties = "SPD" if election_typeBWorLW == "LW" & election_date == td(21apr2002) & Land == "Sachsen_Anhalt"
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "LW" & election_date == td(26mar2006) & Land == "Sachsen_Anhalt"
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "LW" & election_date == td(20mar2011) & Land == "Sachsen_Anhalt"
	replace Incumbent_parties = "CDU + SPD + GRUNE" if election_typeBWorLW == "LW" & election_date == td(13mar2016) & Land == "Sachsen_Anhalt"
	
	//LW : Schleswig-Holstein
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "LW" & election_date == td(08may1988) & Land == "Schleswig_Holstein"
	replace Incumbent_parties = "SPD" if election_typeBWorLW == "LW" & election_date == td(05apr1992) & Land == "Schleswig_Holstein"
	replace Incumbent_parties = "SPD" if election_typeBWorLW == "LW" & election_date == td(24mar1996) & Land == "Schleswig_Holstein"
	replace Incumbent_parties = "SPD + GRUNE" if election_typeBWorLW == "LW" & election_date == td(27feb2000) & Land == "Schleswig_Holstein"
	replace Incumbent_parties = "SPD + GRUNE" if election_typeBWorLW == "LW" & election_date == td(20feb2005) & Land == "Schleswig_Holstein"
	replace Incumbent_parties = "CDU + SPD" if election_typeBWorLW == "LW" & election_date == td(27sep2009) & Land == "Schleswig_Holstein"
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "LW" & election_date == td(06may2012) & Land == "Schleswig_Holstein"
	replace Incumbent_parties = "SPD + GRUNE" if election_typeBWorLW == "LW" & election_date == td(07may2017) & Land == "Schleswig_Holstein"
	
	//LW : Thüringen
	replace Incumbent_parties = "CDU + FDP" if election_typeBWorLW == "LW" & election_date == td(16oct1994) & Land == "Thüringen"
	replace Incumbent_parties = "CDU + SPD" if election_typeBWorLW == "LW" & election_date == td(12sep1999) & Land == "Thüringen"
	replace Incumbent_parties = "CDU" if election_typeBWorLW == "LW" & election_date == td(13jun2004) & Land == "Thüringen"
	replace Incumbent_parties = "CDU + SPD" if election_typeBWorLW == "LW" & election_date == td(30aug2009) & Land == "Thüringen"
	replace Incumbent_parties = "CDU + SPD" if election_typeBWorLW == "LW" & election_date == td(14sep2014) & Land == "Thüringen"
	replace Incumbent_parties = "SPD + DIELINKE + GRUNE" if election_typeBWorLW == "LW" & election_date == td(27oct2019) & Land == "Thüringen"

replace Incumbent_parties = subinstr(Incumbent_parties, " +", ",",.)

*------------------------------------------------------------------------------*

***Generate incumbency dummy for established parties
*Overall
foreach p in SPD CDU FDP GRUNE DIELINKE {
	gen `p'_inc =  strpos( Incumbent_parties , "`p'") > 0
} //p

*BW
foreach p in SPD CDU FDP GRUNE DIELINKE {
	gen `p'_inc_BW =  strpos( Incumbent_parties , "`p'") > 0 if election_typeBWorLW == "BW"
} //p

*LW
foreach p in SPD CDU FDP GRUNE DIELINKE {
	gen `p'_inc_LW =  strpos( Incumbent_parties , "`p'") > 0 if election_typeBWorLW == "LW"
} //p

*------------------------------------------------------------------------------*

***Generate incumbency and opposition percentages
foreach p in SPD CDU FDP GRUNE DIELINKE{
	//BW
	sum `p'_inc_BW
	scalar perc_`p'_inc_BW = r(mean)
	gen perc_`p'_inc_opp = .
	replace perc_`p'_inc_opp = perc_`p'_inc_BW if `p'_inc_BW == 1
	replace perc_`p'_inc_opp = (1 - perc_`p'_inc_BW) if `p'_inc_BW == 0
	//LW
	sum `p'_inc_LW
	scalar perc_`p'_inc_LW = r(mean)
	replace perc_`p'_inc_opp = perc_`p'_inc_LW if `p'_inc_LW == 1
	replace perc_`p'_inc_opp = (1 - perc_`p'_inc_LW) if `p'_inc_LW == 0
} //p

*------------------------------------------------------------------------------*

***Create individual datasets for each party
foreach p in SPD CDU FDP GRUNE DIELINKE{
	preserve
	
		keep election_typeBWorLW `p'_inc perc_`p'_inc_opp
		egen a = group(election_typeBWorLW `p'_inc)
		sort a
		gen Party = "`p'"
		order Party election_typeBWorLW `p'_inc perc_`p'_inc_opp a
		collapse `p'_inc perc_`p'_inc_opp (first) Party election_typeBWorLW, by(a)
		save "${tempdata}/`p'_inc_opp.dta", replace

	restore
} //p

*------------------------------------------------------------------------------*

***Put all parties back together
clear

foreach p in SPD CDU FDP GRUNE DIELINKE{
	append using "${tempdata}/`p'_inc_opp.dta"
	erase "${tempdata}/`p'_inc_opp.dta"
} //p

gen Percentage = .
gen Role = .
foreach p in SPD CDU FDP GRUNE DIELINKE{
	replace Percentage = perc_`p'_inc_opp if Party == "`p'"
	replace Role = `p'_inc if Party == "`p'"
} //p

label define Inc_Opp 1 "Incumbent" 0 "Opposition"
label values Role Inc_Opp

keep Party election_typeBWorLW Percentage Role

replace Percentage = Percentage * 100

*------------------------------------------------------------------------------*

***Bar plot
graph bar Percentage, over(Role) over(election_typeBWorLW) over(Party) ytitle("Percentage (%)") graphregion(color(white)) bgcolor(white)
graph export "${outputs}figure_S3.png", replace

*------------------------------------------------------------------------------*

clear

exit
